package wifiunion.com.notice.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import wifiunion.com.notice.CommonUtils;
import wifiunion.com.notice.Constants;
import wifiunion.com.notice.NoticeRecordContact;
import wifiunion.com.notice.R;
import wifiunion.com.notice.entity.NoticeRecord;

/**
 * Created by Administrator on 2016/11/23.
 */

public class NoticeRecordAdapter extends RecyclerView.Adapter<NoticeRecordMainViewHolder> {

    private Context mContext;

    private List<NoticeRecord> data = new ArrayList<NoticeRecord>();

    private NoticeRecordContact.View mView;

    private View.OnClickListener mItemClick;

    private NoticeRecord record;

//    private


    public NoticeRecordAdapter(NoticeRecordContact.View view, Context context, List<NoticeRecord> dt, View.OnClickListener itemClick) {
        mContext = context;
        data = dt;
        mView = view;
        mItemClick = itemClick;
    }


    @Override
    public NoticeRecordMainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.noticerecord_list_item, parent, false);


        NoticeRecordMainViewHolder cv = new NoticeRecordMainViewHolder(view);


        return cv;
    }

    @Override
    public void onBindViewHolder(NoticeRecordMainViewHolder holder, int position) {


        record = data.get(position);


        holder.mTimetv.setText(CommonUtils.getDateTimeSecondStr(record.getCreatedTime()));

        holder.mDevicetv.setText(record.getDeviceUnique() + "/" + record.getLocationName());
        holder.mTZNRtv.setText(record.getContent());
        holder.mTZDXtv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        holder.mTZDXtv.getPaint().setAntiAlias(true);
//        holder.mTZDXtv.setText(Html.fromHtml("<u>"+"查看"+"</u>"));

        holder.mTZDXtv.setTag(position);
        holder.mTZDXtv.setOnClickListener(mItemClick);

        holder.mTZNRtv.setTag(position);
        holder.mTZNRtv.setOnClickListener(mItemClick);

        holder.mHeaderiv.setTag(R.id.noticerecord_item_header_iv, position);
        holder.mHeaderiv.setOnClickListener(mItemClick);

        Glide.with(mContext).load(Constants.HTTP_URL_IMAGESERVER + record.getPicUrl()).placeholder(R.drawable.mr_head)
                .error(R.drawable.mr_head).centerCrop().into(holder.mHeaderiv);

    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}
